from Platforms.restapifactory import RestAPIFactory


class newOrder:
    def __init__(self,
                 platform, commodity_cur, base_cur, side, ordertype, quantity, price):
        self.order_id = ""
        self.side = side
        self.price = price

        self.original_amount = quantity
        self.remaining_amount = 0
        self.executed_amount = 0

        factory = RestAPIFactory()
        self.platform = factory.get_platform(platform)
        symbol = self.platform.get_symbol(commodity_cur, base_cur)
        if ordertype == 'limit':
            if side == 'buy':
                self.result = self.platform.limit_buy(symbol, quantity, price)
            elif side == 'sell':
                self.result = self.platform.limit_sell(symbol, quantity, price)
        elif ordertype == 'market':
            if side == 'buy':
                self.result = self.platform.market_buy(symbol, quantity, price)
            elif side == 'sell':
                self.result = self.platform.market_sell(symbol, quantity, price)


class CancelOrder:
    def __init__(self, platform, commodity_cur, base_cur, order_id):
        factory = RestAPIFactory()
        self.platform = factory.get_platform(platform)
        symbol = self.platform.get_symbol(commodity_cur, base_cur)
        # symbol = self.platform.get_symbol()
        self.platform.cancel_order(symbol, order_id)
# list of dicitionary. [{"price":"0.02", "side":"buy", "amount_org":"0.05", "amount_rem":"0.01"}]


class ActiveOrders:
    def __init__(self, platform):
        factory = RestAPIFactory()
        self.platform = factory.get_platform(platform)
        self.active_orders = self.platform.get_open_orders()


class CancelAllOrder:
    def __init__(self, platform):
        factory = RestAPIFactory()
        self.platform = factory.get_platform(platform)
        self.result = self.platform.cancel_all_orders()
